Analysis Timestamp:

date()
## [1] "Thu Jun 23 18:06:29 2016"

Dependencies

library(ggplot2, quietly=T)
library(lme4, quietly=T)
library(psych, quietly=T)
## 
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
library(dplyr, quietly=T)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

Raw data processing…

source('./process_tobii_data_bf.R')
auto_process_tobii('ancat-aoi.txt','ancat-phasetiming.txt')
concat_csv('master.csv')

# fix subject names
master <- read.csv('master.csv')
master$ParticipantName <- gsub('[^a-zA-Z0-9]','',master$ParticipantName)
write.csv(master,'master.csv')

# prepare subjects file
subjects <- read.csv('subjects.csv')

prepare_master(subjectfile = './subjects.csv', trialfile = FALSE)

# create clean file
file.copy('master-prepared.csv','master-clean.csv',overwrite = T)

# exclude exclusions
master_clean <- read.csv('master-clean.csv')
master_clean <- master_clean[which(master_clean$Excluded == 0), ]

# get rid of additional Condition.x and use the Condition.y column from
# the subjects file
master_clean <- master_clean[ , -which(names(master_clean) %in% c("Condition.x"))]
names(master_clean)[names(master_clean)=="Condition.y"] <- "Condition"

# add KnownAnimal column
master_clean$KnownAnimal <- 0
master_clean[which(master_clean$Trial == 'UnfamiliarArmadillo' & master_clean$Armadillo == 1), 'KnownAnimal'] <- 1
master_clean[which(master_clean$Trial == 'UnfamiliarFlamingo' & master_clean$Flamingo == 1), 'KnownAnimal'] <- 1
master_clean[which(master_clean$Trial == 'UnfamiliarLizard' & master_clean$Lizard == 1), 'KnownAnimal'] <- 1
master_clean[which(master_clean$Trial == 'UnfamiliarHedgehog' & master_clean$Hedgehog == 1), 'KnownAnimal'] <- 1
master_clean[which(master_clean$Trial == 'UnfamiliarLemur' & master_clean$Lemur == 1), 'KnownAnimal'] <- 1
master_clean[which(master_clean$Trial == 'UnfamiliarRhino' & master_clean$Rhinoceros == 1), 'KnownAnimal'] <- 1

# add KnownVerb column
master_clean$KnownVerb <- 0
master_clean[which(master_clean$Trial == 'UnfamiliarHedgehog' & master_clean$Condition == 'informative' & master_clean$Sleep == 1), 'KnownVerb'] <- 1
master_clean[which(master_clean$Trial == 'UnfamiliarArmadillo' & master_clean$Condition == 'informative' & master_clean$Look == 1), 'KnownVerb'] <- 1
master_clean[which(master_clean$Trial == 'UnfamiliarLizard' & master_clean$Condition == 'informative' & master_clean$Cry == 1), 'KnownVerb'] <- 1
master_clean[which(master_clean$Trial == 'UnfamiliarFlamingo' & master_clean$Condition == 'informative' & master_clean$Dance == 1), 'KnownVerb'] <- 1
master_clean[which(master_clean$Trial == 'UnfamiliarLemur' & master_clean$Condition == 'informative' & master_clean$Eat == 1), 'KnownVerb'] <- 1
master_clean[which(master_clean$Trial == 'UnfamiliarRhino' & master_clean$Condition == 'informative' & master_clean$Drink == 1), 'KnownVerb'] <- 1

# add Verb column
master_clean$Verb <- ''
master_clean[which(master_clean$Trial == 'UnfamiliarHedgehog'), 'Verb'] <- 'Sleep'
master_clean[which(master_clean$Trial == 'UnfamiliarArmadillo'), 'Verb'] <- 'Look'
master_clean[which(master_clean$Trial == 'UnfamiliarLizard'), 'Verb'] <- 'Cry'
master_clean[which(master_clean$Trial == 'UnfamiliarFlamingo'), 'Verb'] <- 'Dance'
master_clean[which(master_clean$Trial == 'UnfamiliarLemur'), 'Verb'] <- 'Eat'
master_clean[which(master_clean$Trial == 'UnfamiliarRhino'), 'Verb'] <- 'Drink'

# re-name factor levels.
levels(master_clean$Condition) <- c('Informative','Neutral')

# re-factor to get rid of any bad condition names which no longer exist in the dataset
# master_clean$Condition <- factor(as.character(trim(master_clean$Condition)))

#write.csv(master_clean,'master-clean.csv',row.names = FALSE)
save(master_clean,file='master-clean.Rdata')

Load and set data options for eyetrackingR library.

#devtools::install_github('jwdink/eyetrackingR')
library(eyetrackingR)

data <- make_eyetrackingr_data(master_clean, 
                       participant_column = "ParticipantName",
                       trial_column = "Trial",
                       time_column = "TimeFromPhaseOnset",
                       trackloss_column = "TrackLoss",
                       aoi_columns = c('Animate','Inanimate'),
                       treat_non_aoi_looks_as_missing = TRUE
)
## Converting Trackloss to proper type.
## Warning in check_then_convert(x, is.logical2, as.logical, "Trackloss"):
## Found NAs in trackloss column, these will be treated as TRACKLOSS=FALSE.
## Converting AOI to proper type.
## Converting AOI to proper type.
# add kind of trial
data$TrialType <- ifelse(grepl('Unfamiliar',data$Trial), 'Unfamiliar','Familiar')
data$TrialType <- factor(data$TrialType)

# add Target for Familiar trials
data$Target <- as.factor( ifelse(test = grepl('(Spoon|Bottle)', data$Trial), 
                                       yes = 'Inanimate', 
                                       no  = 'Animate') )

# convert age
data$Age <- as.numeric(as.character(data$Age))

Zoom in to response window

response_window <- subset_by_window(data, window_start_time = 15500, window_end_time = 21000, rezero=TRUE, remove=TRUE)
## Avg. window length in new data will be 5500

Familiar Trials

familiar_raw <- filter(response_window, TrialType == 'Familiar')

Clean by trackloss

trackloss <- trackloss_analysis(data = familiar_raw)

# set a threshold for amount of trackloss that is acceptable
prop_thresh <- mean(trackloss$TracklossForTrial) + 2*sd(trackloss$TracklossForTrial)

familiar <- clean_by_trackloss(data = familiar_raw, trial_prop_thresh = prop_thresh)
## Performing Trackloss Analysis...
## Will exclude trials whose trackloss proportion is greater than : 0.636088292477149
##  ...removed  18  trials.
trackloss_clean <- trackloss_analysis(data = familiar)
trackloss_clean_subjects <- unique(trackloss_clean[, c('ParticipantName','TracklossForParticipant')])

# get mean samples contributed per trials, with SD
mean(1 - trackloss_clean_subjects$TracklossForParticipant)
## [1] 0.828145
sd(1- trackloss_clean_subjects$TracklossForParticipant)
## [1] 0.1075668
# get number of trials contributed by participant
interim_summary <- describe_data(familiar, 'Animate', c('ParticipantName'))
interim_summary
## Source: local data frame [48 x 8]
## 
##    ParticipantName      Mean        SD       Var   Min   Max     N
##             <fctr>     <dbl>     <dbl>     <dbl> <dbl> <dbl> <int>
## 1         ANCAT177 0.5577812 0.4970332 0.2470420     0     1   990
## 2         ANCAT180 0.5454545 0.4981655 0.2481689     0     1  1650
## 3         ANCAT181 0.4929835 0.5001034 0.2501034     0     1  1980
## 4         ANCAT183 0.4592760 0.4986209 0.2486228     0     1  1320
## 5         ANCAT184 0.6544811 0.4756774 0.2262690     0     1  1980
## 6         ANCAT190 0.7213325 0.4484872 0.2011408     0     1  1980
## 7         ANCAT191 0.7262314 0.4460194 0.1989333     0     1  1980
## 8         ANCAT194 0.6402003 0.4801133 0.2305088     0     1  1980
## 9         ANCAT195 0.6763902 0.4680665 0.2190862     0     1  1320
## 10        ANCAT198 0.6895735 0.4628054 0.2141888     0     1  1980
## ..             ...       ...       ...       ...   ...   ...   ...
## Variables not shown: NumTrials <int>.
# remove participants who have less than 3 trials of either type
subjects_to_remove <- as.character(filter(interim_summary, NumTrials < 3)$ParticipantName)

familiar <- familiar %>%
                         filter(!(ParticipantName %in% subjects_to_remove))

# final counts:
final_summary <- describe_data(familiar, 'Animate', c('ParticipantName'))
final_summary
## Source: local data frame [48 x 8]
## 
##    ParticipantName      Mean        SD       Var   Min   Max     N
##             <fctr>     <dbl>     <dbl>     <dbl> <dbl> <dbl> <int>
## 1         ANCAT177 0.5577812 0.4970332 0.2470420     0     1   990
## 2         ANCAT180 0.5454545 0.4981655 0.2481689     0     1  1650
## 3         ANCAT181 0.4929835 0.5001034 0.2501034     0     1  1980
## 4         ANCAT183 0.4592760 0.4986209 0.2486228     0     1  1320
## 5         ANCAT184 0.6544811 0.4756774 0.2262690     0     1  1980
## 6         ANCAT190 0.7213325 0.4484872 0.2011408     0     1  1980
## 7         ANCAT191 0.7262314 0.4460194 0.1989333     0     1  1980
## 8         ANCAT194 0.6402003 0.4801133 0.2305088     0     1  1980
## 9         ANCAT195 0.6763902 0.4680665 0.2190862     0     1  1320
## 10        ANCAT198 0.6895735 0.4628054 0.2141888     0     1  1980
## ..             ...       ...       ...       ...   ...   ...   ...
## Variables not shown: NumTrials <int>.
# how many participants?
length(unique(final_summary$ParticipantName))
## [1] 48
# how many trials?
mean(final_summary$NumTrials)
## [1] 5.625
sd(final_summary$NumTrials)
## [1] 0.7614376

Summarize

(familiar_summary <- familiar %>%
                    group_by(ParticipantName, Target) %>%
                    summarise(Animate = mean(Animate, na.rm=TRUE),
                              NTrials = length(unique(Trial))) %>%
                    ungroup() %>%
                    group_by(Target) %>%
                    summarise(MeanAnimate = mean(Animate),
                              SDAnimate = sd(Animate),
                              N = n(),
                              MeanTrials = mean(NTrials),
                              SDTrials = sd(NTrials)) %>%
                    ungroup())
## Source: local data frame [2 x 6]
## 
##      Target MeanAnimate SDAnimate     N MeanTrials  SDTrials
##      <fctr>       <dbl>     <dbl> <int>      <dbl>     <dbl>
## 1   Animate   0.7717944 0.1163495    48     3.6875 0.6890095
## 2 Inanimate   0.3706804 0.1511891    48     1.9375 0.2446230
subjects <- familiar %>%
            distinct(ParticipantName,Age_Group,Age,Sex,Condition) %>%
            group_by(Condition,Age_Group) %>%
            summarise(N=length(ParticipantName), MeanAge = mean(Age,na.rm=TRUE), N_Males = length(Sex[Sex=='M'])) %>%
            ungroup()

subjects
## Source: local data frame [2 x 5]
## 
##     Condition Age_Group     N  MeanAge N_Males
##        <fctr>    <fctr> <int>    <dbl>   <int>
## 1 Informative 24-months    24 24.13667      11
## 2     Neutral 24-months    24 24.22208      12

Window Analysis

familiar_summary <- describe_data(familiar, describe_column='Animate', group_columns=c('Target'))
familiar_summary
## Source: local data frame [2 x 8]
## 
##      Target      Mean        SD       Var   Min   Max     N NumTrials
##      <fctr>     <dbl>     <dbl>     <dbl> <dbl> <dbl> <int>     <int>
## 1   Animate 0.7706458 0.4204218 0.1767545     0     1 58410         4
## 2 Inanimate 0.3725520 0.4834936 0.2337660     0     1 30690         2
# agg by subject
familiar_sub <- make_time_window_data(familiar, 
                                       aois='Animate',
                                       predictor_columns=c('Target','Age','MCDI_Total'),
                                       summarize_by = "ParticipantName")

# take a quick peek at data
ggplot(familiar_sub, aes(x=Target,y=Prop,group=ParticipantName)) +
                      geom_point() +
                      geom_line()

# simple paired t-test between conditions
t.test(ArcSin ~ Target, data=familiar_sub, paired=TRUE)
## 
##  Paired t-test
## 
## data:  ArcSin by Target
## t = 12.2, df = 47, p-value = 3.592e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.3695234 0.5154568
## sample estimates:
## mean of the differences 
##               0.4424901
# mixed-effects model
familiar_trial <- make_time_window_data(familiar, 
                                         aois='Animate', 
                                         predictor_columns=c('Target','Age'))

# sum-code and center predictors
familiar_trial$TargetC <- ifelse(familiar_trial$Target == 'Animate', .5, -.5)
familiar_trial$TargetC <- familiar_trial$TargetC - mean(familiar_trial$TargetC)

# mixed-effects linear model on subject*trial data
model <- lmer(ArcSin ~ TargetC + (1 | Trial) + (1 | ParticipantName), data = familiar_trial, REML = FALSE)
summary(model)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: ArcSin ~ TargetC + (1 | Trial) + (1 | ParticipantName)
##    Data: familiar_trial
## 
##      AIC      BIC   logLik deviance df.resid 
##      7.7     25.7      1.2     -2.3      265 
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.96076 -0.65849 -0.01642  0.68506  2.41056 
## 
## Random effects:
##  Groups          Name        Variance Std.Dev.
##  ParticipantName (Intercept) 0.004992 0.07066 
##  Trial           (Intercept) 0.008849 0.09407 
##  Residual                    0.051270 0.22643 
## Number of obs: 270, groups:  ParticipantName, 48; Trial, 6
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  0.95379    0.04208  22.665
## TargetC      0.47546    0.08649   5.497
## 
## Correlation of Fixed Effects:
##         (Intr)
## TargetC -0.020
drop1(model,~.,test="Chi")
## Single term deletions
## 
## Model:
## ArcSin ~ TargetC + (1 | Trial) + (1 | ParticipantName)
##         Df     AIC    LRT  Pr(Chi)   
## <none>      7.6885                   
## TargetC  1 16.4630 10.775 0.001029 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Growth Curve Analysis

# aggregate across trials within subjects in time analysis
response_time <- make_time_sequence_data(familiar, time_bin_size = 100, 
                                 predictor_columns = c("Target"),
                                 aois = "Animate"
                            )

# visualize time results
plot(response_time, predictor_column = "Target") + 
  theme_light() +
  coord_cartesian(ylim = c(0,1))
## Warning: Removed 95 rows containing non-finite values (stat_summary).

## Warning: Removed 95 rows containing non-finite values (stat_summary).

# sum-code and center our predictor:
response_time$TargetC <- ifelse(response_time$Target == 'Animate', .5, -.5)
response_time$TargetC <- response_time$TargetC - mean(response_time$TargetC)

# Construct model
model_time_sequence <- lmer(ArcSin ~ TargetC*(ot1+ot2+ot3+ot4) + (1 + ot1 + ot2 + ot3 + ot4 | Trial) + (1 + ot1 + ot2 + ot3 + ot4 | ParticipantName), data = response_time, REML = FALSE)
summary(model_time_sequence)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: ArcSin ~ TargetC * (ot1 + ot2 + ot3 + ot4) + (1 + ot1 + ot2 +  
##     ot3 + ot4 | Trial) + (1 + ot1 + ot2 + ot3 + ot4 | ParticipantName)
##    Data: response_time
## 
##      AIC      BIC   logLik deviance df.resid 
##  25057.8  25364.6 -12487.9  24975.8    13092 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.7614 -0.7711  0.1746  0.6886  2.5880 
## 
## Random effects:
##  Groups          Name        Variance Std.Dev. Corr                   
##  ParticipantName (Intercept) 0.01856  0.1363                          
##                  ot1         0.80430  0.8968    0.44                  
##                  ot2         0.54283  0.7368   -0.20  0.13            
##                  ot3         0.53798  0.7335   -0.22 -0.31 -0.35      
##                  ot4         0.38425  0.6199    0.27 -0.09  0.02  0.03
##  Trial           (Intercept) 0.01192  0.1092                          
##                  ot1         0.06848  0.2617    0.42                  
##                  ot2         0.02680  0.1637   -0.12  0.00            
##                  ot3         0.07742  0.2783   -0.19 -0.01 -0.94      
##                  ot4         0.15610  0.3951    0.40 -0.46  0.51 -0.71
##  Residual                    0.37614  0.6133                          
## Number of obs: 13133, groups:  ParticipantName, 48; Trial, 6
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  0.97887    0.04904  19.960
## TargetC      0.60317    0.09522   6.334
## ot1         -0.57118    0.17313  -3.299
## ot2          0.19319    0.13241   1.459
## ot3         -0.12104    0.16080  -0.753
## ot4          0.04510    0.18908   0.238
## TargetC:ot1 -1.20442    0.24242  -4.968
## TargetC:ot2 -1.12423    0.16551  -6.793
## TargetC:ot3  1.11403    0.25556   4.359
## TargetC:ot4 -0.70774    0.35262  -2.007
## 
## Correlation of Fixed Effects:
##             (Intr) TargtC ot1    ot2    ot3    ot4    TrgC:1 TrgC:2 TrgC:3
## TargetC     -0.021                                                        
## ot1          0.372 -0.005                                                 
## ot2         -0.116  0.002  0.088                                          
## ot3         -0.183  0.003 -0.157 -0.516                                   
## ot4          0.362 -0.008 -0.275  0.228 -0.413                            
## TargetC:ot1 -0.007  0.397 -0.010  0.003  0.002  0.008                     
## TargetC:ot2  0.003 -0.097  0.003 -0.004  0.016 -0.007  0.014              
## TargetC:ot3  0.004 -0.182  0.001  0.012 -0.013  0.015 -0.009 -0.751       
## TargetC:ot4 -0.008  0.385  0.006 -0.005  0.013 -0.018 -0.420  0.425 -0.645
plot(response_time, predictor_column = "Target", dv = "ArcSin", model = model_time_sequence) + theme_light()
## Warning: Removed 95 rows containing non-finite values (stat_summary).

## Warning: Removed 95 rows containing non-finite values (stat_summary).

Bootstrapped Spline Analysis

response_familiar_time <- make_time_sequence_data(familiar,
                                  time_bin_size = 10, 
                                  predictor_columns = c("Target"),
                                  aois = "Animate",
                                  summarize_by = "ParticipantName"
                            )

# visualize timecourse
plot(response_familiar_time, predictor_column = "Target") + 
  theme_light() +
  coord_cartesian(ylim = c(0,1))
## Warning: Removed 1046 rows containing non-finite values (stat_summary).

## Warning: Removed 1046 rows containing non-finite values (stat_summary).

# bootstrap with smoothing splines
bootstrapped_familiar <- make_boot_splines_data(response_familiar_time, 
                                              predictor_column = 'Target', 
                                              within_subj = TRUE, 
                                              bs_samples = 5000, 
                                              alpha = .05,
                                              smoother = "smooth.spline")
## Warning: Calling boot-splines from this function is deprecated. Please use
## `analyze_time_bins` for boot-splines.
plot(bootstrapped_familiar)
## Plotting within-subjects differences...

# show us the divergences where p < .05
bootstrap_analysis_familiar <- analyze_boot_splines(bootstrapped_familiar)
## Warning: Calling boot-splines from this function is deprecated. Please use
## `analyze_time_bins` for boot-splines.
summary(bootstrap_analysis_familiar)
## Divergences:
## 1:   170 - 5330

Cluster Analysis

alpha = .20
num_sub = length(unique((familiar$ParticipantName)))
threshold_t = qt(p = 1 - alpha/2, 
                 df = num_sub-1)

df_timeclust <- make_time_cluster_data(response_familiar_time, 
                                      test= "t.test",
                                      paired = TRUE,
                                      predictor_column = "Target", 
                                      threshold = threshold_t,
                                      formula = ArcSin ~ Target) 

plot(df_timeclust) +
  ylab("T-Statistic")

summary(df_timeclust)
## Test Type:    t.test 
## Predictor:    Target 
## Formula:  ArcSin ~ Target 
## Summary of Clusters ======
##   Cluster Direction SumStatistic StartTime EndTime
## 1       1  Positive    1823.7147       200    4440
## 2       2  Positive     147.3181      4460    5360
clust_analysis <- analyze_time_clusters(df_timeclust, within_subj=TRUE, paired=TRUE, samples=5000, parallel=TRUE)
clust_analysis
## Test Type:    t.test 
## Predictor:    Target 
## Formula:  ArcSin ~ Target 
## Null Distribution   ====== 
##  Mean:        -0.1405 
##  2.5%:        -176.2248 
## 97.5%:        185.4092 
## Summary of Clusters ======
##   Cluster Direction SumStatistic StartTime EndTime Probability
## 1       1  Positive    1823.7147       200    4440       0.000
## 2       2  Positive     147.3181      4460    5360       0.076
plot(clust_analysis)

Onset-contingent Analysis

# recode AOIs to target & distractor
familiar$TrialTarget <- ifelse(familiar$Target == 'Animate', familiar$Animate, familiar$Inanimate)
familiar$TrialDistractor <- ifelse(familiar$Target == 'Animate', familiar$Inanimate, familiar$Animate)

onsets <- make_onset_data(familiar, onset_time = 0, 
                          fixation_window_length = 100, target_aoi='TrialTarget')
## Warning in make_onset_data(familiar, onset_time = 0, fixation_window_length = 100, : Smoothing in make_onset_data() using fixation_window_length_rows is experimental. We
##             recommend looking closely at the output to validate it.
# participants' ability to orient to the trial target overall:
plot(onsets) + theme(legend.text=element_text(size=5))

onset_switches <- make_switch_data(onsets, predictor_columns = c("Target","TrialNumber"))

# visualize subject's switch times
plot(onset_switches)
## Warning: Removed 21 rows containing non-finite values (stat_boxplot).
## Warning: Removed 21 rows containing missing values (geom_point).

# center predictor:
onset_switches$FirstAOIC <- ifelse(onset_switches$FirstAOI == 'TrialTarget', .5, -.5)
onset_switches$FirstAOIC <- onset_switches$FirstAOIC - mean(onset_switches$FirstAOIC, na.rm=TRUE)
onset_switches$TargetC <- ifelse(onset_switches$Target == 'Animate', .5, -.5)
onset_switches$TargetC <- onset_switches$TargetC - mean(onset_switches$TargetC)
onset_switches$TrialNumberC <- onset_switches$TrialNumber - mean(onset_switches$TrialNumber)

# build model:
model_switches <- lmer(FirstSwitch ~ (FirstAOIC+TargetC+TrialNumberC)^2 + (1 | Trial) + (1 + TargetC | ParticipantName), data=onset_switches, REML=FALSE)
summary(model_switches)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: 
## FirstSwitch ~ (FirstAOIC + TargetC + TrialNumberC)^2 + (1 | Trial) +  
##     (1 + TargetC | ParticipantName)
##    Data: onset_switches
## 
##      AIC      BIC   logLik deviance df.resid 
##   3737.4   3778.3  -1856.7   3713.4      211 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.9190 -0.5383 -0.1554  0.4629  4.0785 
## 
## Random effects:
##  Groups          Name        Variance Std.Dev. Corr
##  ParticipantName (Intercept) 128394   358.3        
##                  TargetC     118015   343.5    1.00
##  Trial           (Intercept)  15464   124.4        
##  Residual                    874740   935.3        
## Number of obs: 223, groups:  ParticipantName, 48; Trial, 6
## 
## Fixed effects:
##                        Estimate Std. Error t value
## (Intercept)            1268.816    107.676  11.784
## FirstAOIC              1578.763    148.692  10.618
## TargetC                 486.504    210.195   2.315
## TrialNumberC            128.042     54.412   2.353
## FirstAOIC:TargetC      1496.848    330.901   4.524
## FirstAOIC:TrialNumberC    2.122    108.680   0.020
## TargetC:TrialNumberC    204.435    128.268   1.594
## 
## Correlation of Fixed Effects:
##             (Intr) FrAOIC TargtC TrlNmC FAOIC:TC FAOIC:TN
## FirstAOIC   -0.016                                       
## TargetC      0.010 -0.247                                
## TrialNumbrC  0.008 -0.023 -0.319                         
## FrstAOIC:TC -0.272  0.127  0.146  0.100                  
## FrsAOIC:TNC  0.129  0.009 -0.022 -0.131 -0.391           
## TrgtC:TrlNC -0.330  0.038  0.224  0.097  0.143   -0.487
drop1(model_switches,~.,test="Chi")
## Single term deletions
## 
## Model:
## FirstSwitch ~ (FirstAOIC + TargetC + TrialNumberC)^2 + (1 | Trial) + 
##     (1 + TargetC | ParticipantName)
##                        Df    AIC    LRT   Pr(Chi)    
## <none>                    3737.4                     
## FirstAOIC               1 3818.9 83.454 < 2.2e-16 ***
## TargetC                 1 3739.3  3.855   0.04959 *  
## TrialNumberC            1 3739.5  4.128   0.04218 *  
## FirstAOIC:TargetC       1 3754.6 19.215 1.168e-05 ***
## FirstAOIC:TrialNumberC  1 3735.4  0.000   0.98618    
## TargetC:TrialNumberC    1 3737.9  2.465   0.11644    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Unfamiliar Trials

unfamiliar_raw <- filter(response_window, TrialType == 'Unfamiliar')

Clean by trackloss

trackloss <- trackloss_analysis(data = unfamiliar_raw)

# set a threshold for amount of trackloss that is acceptable
prop_thresh <- mean(trackloss$TracklossForTrial) + 2*sd(trackloss$TracklossForTrial)

unfamiliar <- clean_by_trackloss(data = unfamiliar_raw, trial_prop_thresh = prop_thresh)
## Performing Trackloss Analysis...
## Will exclude trials whose trackloss proportion is greater than : 0.705477220469878
##  ...removed  16  trials.
trackloss_clean <- trackloss_analysis(data = unfamiliar)
trackloss_clean_subjects <- unique(trackloss_clean[, c('ParticipantName','TracklossForParticipant')])

# get mean samples contributed per trials, with SD
mean(1 - trackloss_clean_subjects$TracklossForParticipant)
## [1] 0.8094455
sd(1- trackloss_clean_subjects$TracklossForParticipant)
## [1] 0.1312352
# get number of trials contributed by participant
interim_summary <- describe_data(unfamiliar, 'Animate', c('ParticipantName'))
interim_summary
## Source: local data frame [48 x 8]
## 
##    ParticipantName      Mean        SD        Var   Min   Max     N
##             <fctr>     <dbl>     <dbl>      <dbl> <dbl> <dbl> <int>
## 1         ANCAT177 0.6269336 0.4838397 0.23410088     0     1  1980
## 2         ANCAT180 0.7254733 0.4464676 0.19933332     0     1  1980
## 3         ANCAT181 0.4805492 0.4997645 0.24976455     0     1  1980
## 4         ANCAT183 0.2767857 0.4478096 0.20053348     0     1  1320
## 5         ANCAT184 0.6773802 0.4676204 0.21866886     0     1  1980
## 6         ANCAT190 0.6974044 0.4595386 0.21117576     0     1  1980
## 7         ANCAT191 0.5756894 0.4943770 0.24440866     0     1  1980
## 8         ANCAT194 0.3730018 0.4838175 0.23407934     0     1  1650
## 9         ANCAT195 0.5646863 0.4959357 0.24595225     0     1  1980
## 10        ANCAT198 0.9373454 0.2424406 0.05877744     0     1  1650
## ..             ...       ...       ...        ...   ...   ...   ...
## Variables not shown: NumTrials <int>.
# remove participants who have less than 3 trials of either type
subjects_to_remove <- as.character(filter(interim_summary, NumTrials < 3)$ParticipantName)

unfamiliar <- unfamiliar %>%
                         filter(!(ParticipantName %in% subjects_to_remove))

# final counts:
final_summary <- describe_data(unfamiliar, 'Animate', c('ParticipantName'))
final_summary
## Source: local data frame [48 x 8]
## 
##    ParticipantName      Mean        SD        Var   Min   Max     N
##             <fctr>     <dbl>     <dbl>      <dbl> <dbl> <dbl> <int>
## 1         ANCAT177 0.6269336 0.4838397 0.23410088     0     1  1980
## 2         ANCAT180 0.7254733 0.4464676 0.19933332     0     1  1980
## 3         ANCAT181 0.4805492 0.4997645 0.24976455     0     1  1980
## 4         ANCAT183 0.2767857 0.4478096 0.20053348     0     1  1320
## 5         ANCAT184 0.6773802 0.4676204 0.21866886     0     1  1980
## 6         ANCAT190 0.6974044 0.4595386 0.21117576     0     1  1980
## 7         ANCAT191 0.5756894 0.4943770 0.24440866     0     1  1980
## 8         ANCAT194 0.3730018 0.4838175 0.23407934     0     1  1650
## 9         ANCAT195 0.5646863 0.4959357 0.24595225     0     1  1980
## 10        ANCAT198 0.9373454 0.2424406 0.05877744     0     1  1650
## ..             ...       ...       ...        ...   ...   ...   ...
## Variables not shown: NumTrials <int>.
# how many participants?
length(unique(final_summary$ParticipantName))
## [1] 48
# how many trials?
mean(final_summary$NumTrials)
## [1] 5.666667
sd(final_summary$NumTrials)
## [1] 0.6631111

Summarize

(unfamiliar_summary <- unfamiliar %>%
                    group_by(ParticipantName, Target) %>%
                    summarise(Animate = mean(Animate, na.rm=TRUE),
                              NTrials = length(unique(Trial))) %>%
                    ungroup() %>%
                    group_by(Target) %>%
                    summarise(MeanAnimate = mean(Animate),
                              SDAnimate = sd(Animate),
                              N = n(),
                              MeanTrials = mean(NTrials),
                              SDTrials = sd(NTrials)) %>%
                    ungroup())
## Source: local data frame [1 x 6]
## 
##    Target MeanAnimate SDAnimate     N MeanTrials  SDTrials
##    <fctr>       <dbl>     <dbl> <int>      <dbl>     <dbl>
## 1 Animate   0.5821864 0.1442839    48   5.666667 0.6631111
subjects <- unfamiliar %>%
            distinct(ParticipantName,Age_Group,Age,Sex,Condition) %>%
            group_by(Condition,Age_Group) %>%
            summarise(N=length(ParticipantName), MeanAge = mean(Age,na.rm=TRUE), N_Males = length(Sex[Sex=='M'])) %>%
            ungroup()

subjects
## Source: local data frame [2 x 5]
## 
##     Condition Age_Group     N  MeanAge N_Males
##        <fctr>    <fctr> <int>    <dbl>   <int>
## 1 Informative 24-months    24 24.13667      11
## 2     Neutral 24-months    24 24.22208      12

Window Analysis

unfamiliar_summary <- describe_data(unfamiliar, describe_column='Animate', group_columns=c('Condition'))
unfamiliar_summary
## Source: local data frame [2 x 8]
## 
##     Condition      Mean        SD       Var   Min   Max     N NumTrials
##        <fctr>     <dbl>     <dbl>     <dbl> <dbl> <dbl> <int>     <int>
## 1 Informative 0.6322832 0.4821904 0.2325075     0     1 45210         6
## 2     Neutral 0.5536108 0.4971243 0.2471326     0     1 44550         6
# agg by subject
unfamiliar_sub <- make_time_window_data(unfamiliar, 
                                       aois='Animate',
                                       predictor_columns=c('Condition','Age','MCDI_Total'),
                                       summarize_by = "ParticipantName")

# take a quick peek at data
ggplot(unfamiliar_sub, aes(x=Condition,y=Prop)) +
                      geom_boxplot() +
                      geom_point()

# simple paired t-test between conditions
t.test(ArcSin ~ Condition, data=unfamiliar_sub, var.equal=T)
## 
##  Two Sample t-test
## 
## data:  ArcSin by Condition
## t = 2.3296, df = 46, p-value = 0.02427
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.01354537 0.18573446
## sample estimates:
## mean in group Informative     mean in group Neutral 
##                 0.9225841                 0.8229442
# mixed-effects model
unfamiliar_trial <- make_time_window_data(unfamiliar, 
                                         aois='Animate', 
                                         predictor_columns=c('Condition','Age'))

# sum-code and center predictors
unfamiliar_trial$ConditionC <- ifelse(unfamiliar_trial$Condition == 'Informative', .5, -.5)
unfamiliar_trial$ConditionC <- unfamiliar_trial$ConditionC - mean(unfamiliar_trial$ConditionC)

unfamiliar_trial$AgeC <- unfamiliar_trial$Age - mean(unfamiliar_trial$Age,na.rm=T)

# mixed-effects linear model on subject*trial data
model <- lmer(ArcSin ~ ConditionC + (1 | Trial) + (1 | ParticipantName), data = unfamiliar_trial, REML = FALSE)
summary(model)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: ArcSin ~ ConditionC + (1 | Trial) + (1 | ParticipantName)
##    Data: unfamiliar_trial
## 
##      AIC      BIC   logLik deviance df.resid 
##    146.1    164.1    -68.0    136.1      267 
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.61248 -0.56946 -0.05782  0.56935  2.56757 
## 
## Random effects:
##  Groups          Name        Variance Std.Dev.
##  ParticipantName (Intercept) 0.011200 0.10583 
##  Trial           (Intercept) 0.008665 0.09309 
##  Residual                    0.084348 0.29043 
## Number of obs: 272, groups:  ParticipantName, 48; Trial, 6
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  0.90420    0.04462  20.266
## ConditionC   0.10516    0.04672   2.251
## 
## Correlation of Fixed Effects:
##            (Intr)
## ConditionC 0.001
drop1(model,~.,test="Chi")
## Single term deletions
## 
## Model:
## ArcSin ~ ConditionC + (1 | Trial) + (1 | ParticipantName)
##            Df    AIC    LRT Pr(Chi)  
## <none>        146.10                 
## ConditionC  1 148.93 4.8349 0.02789 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Growth Curve Analysis

# aggregate across trials within subjects in time analysis
response_time <- make_time_sequence_data(unfamiliar, time_bin_size = 100, 
                                 predictor_columns = c("Condition","Age_Group"),
                                 aois = "Animate"
                            )

# visualize time results
plot(response_time, predictor_column = "Condition") + 
  theme_light() +
  coord_cartesian(ylim = c(0,1))
## Warning: Removed 7 rows containing non-finite values (stat_summary).

## Warning: Removed 7 rows containing non-finite values (stat_summary).

response_time_sub <- response_time %>%
                     group_by(ParticipantName,Condition,Age_Group,Time) %>%
                     summarise(Prop=mean(Prop,na.rm=TRUE)) %>%
                     ungroup()

ggplot(response_time_sub, aes(x=Time, y=Prop, color=Condition, fill=Condition)) +
              stat_summary(fun.y='mean', geom='line') +
              stat_summary(fun.data='mean_cl_normal', geom='ribbon', alpha=.3, color=NA, fun.args=list(mult=1)) +
              facet_grid(~Age_Group)
## Warning: Removed 7 rows containing non-finite values (stat_summary).

## Warning: Removed 7 rows containing non-finite values (stat_summary).

# sum-code and center our predictor:
response_time$ConditionC <- ifelse(response_time$Condition == 'Informative', .5, -.5)
response_time$ConditionC <- response_time$ConditionC - mean(response_time$ConditionC)

# Construct model
model_time_sequence <- lmer(ArcSin ~ ConditionC*(ot1+ot2+ot3+ot4) + (1 + ot1 + ot2 + ot3 + ot4 | Trial) + (1 + ot1 + ot2 + ot3 + ot4 | ParticipantName), data = response_time, REML = FALSE)
summary(model_time_sequence)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: ArcSin ~ ConditionC * (ot1 + ot2 + ot3 + ot4) + (1 + ot1 + ot2 +  
##     ot3 + ot4 | Trial) + (1 + ot1 + ot2 + ot3 + ot4 | ParticipantName)
##    Data: response_time
## 
##      AIC      BIC   logLik deviance df.resid 
##  26893.8  27200.1 -13405.9  26811.8    12915 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.0072 -0.8906  0.2090  0.8247  2.4119 
## 
## Random effects:
##  Groups          Name        Variance Std.Dev. Corr                   
##  ParticipantName (Intercept) 0.03746  0.1936                          
##                  ot1         1.39348  1.1805   -0.15                  
##                  ot2         1.04744  1.0234   -0.23  0.32            
##                  ot3         0.77615  0.8810   -0.31 -0.39 -0.06      
##                  ot4         0.70943  0.8423   -0.07 -0.26 -0.64  0.15
##  Trial           (Intercept) 0.01680  0.1296                          
##                  ot1         0.11053  0.3325   -0.12                  
##                  ot2         0.08356  0.2891    0.68 -0.71            
##                  ot3         0.11875  0.3446    0.38 -0.55  0.31      
##                  ot4         0.12691  0.3562    0.48 -0.53  0.70  0.12
##  Residual                    0.44180  0.6647                          
## Number of obs: 12956, groups:  ParticipantName, 48; Trial, 6
## 
## Fixed effects:
##                Estimate Std. Error t value
## (Intercept)     0.90988    0.06016  15.126
## ConditionC      0.11494    0.05721   2.009
## ot1            -0.66152    0.22274  -2.970
## ot2             0.03497    0.19464   0.180
## ot3             0.33796    0.19503   1.733
## ot4             0.04879    0.19490   0.250
## ConditionC:ot1 -0.48622    0.35312  -1.377
## ConditionC:ot2 -0.08882    0.30952  -0.287
## ConditionC:ot3  0.38461    0.27006   1.424
## ConditionC:ot4 -0.13991    0.25937  -0.539
## 
## Correlation of Fixed Effects:
##             (Intr) CndtnC ot1    ot2    ot3    ot4    CndC:1 CndC:2 CndC:3
## ConditionC   0.004                                                        
## ot1         -0.116  0.001                                                 
## ot2          0.284  0.000 -0.070                                          
## ot3          0.148 -0.002 -0.432  0.114                                   
## ot4          0.294  0.000 -0.369  0.014  0.132                            
## ConditnC:t1  0.001 -0.134  0.007  0.003 -0.001 -0.001                     
## ConditnC:t2  0.000 -0.214  0.003  0.007  0.002 -0.001  0.306              
## ConditnC:t3 -0.001 -0.289 -0.001  0.003  0.007  0.003 -0.348 -0.041       
## ConditnC:t4  0.000 -0.061 -0.001 -0.002  0.003  0.006 -0.239 -0.574  0.148
plot(response_time, predictor_column = "Condition", dv = "ArcSin", model = model_time_sequence) + theme_light()
## Warning: Removed 7 rows containing non-finite values (stat_summary).

## Warning: Removed 7 rows containing non-finite values (stat_summary).

Bootstrapped Spline Analysis

response_unfamiliar_time <- make_time_sequence_data(unfamiliar,
                                  time_bin_size = 10, 
                                  predictor_columns = c("Condition","Age_Group"),
                                  aois = "Animate",
                                  summarize_by = "ParticipantName"
                            )

# visualize timecourse
plot(response_unfamiliar_time, predictor_column = "Condition") + 
  theme_light() +
  coord_cartesian(ylim = c(0,1))
## Warning: Removed 109 rows containing non-finite values (stat_summary).

## Warning: Removed 109 rows containing non-finite values (stat_summary).

# get rid of NA's so we can use splines
response_unfamiliar_time_nonas <- response_unfamiliar_time[!is.na(response_unfamiliar_time$Prop), ]

# bootstrap with smoothing splines
bootstrapped_unfamiliar <- make_boot_splines_data(response_unfamiliar_time_nonas, 
                                              predictor_column = 'Condition', 
                                              within_subj = FALSE, 
                                              bs_samples = 5000, 
                                              alpha = .05,
                                              smoother = "smooth.spline")
## Warning: Calling boot-splines from this function is deprecated. Please use
## `analyze_time_bins` for boot-splines.
plot(bootstrapped_unfamiliar)

# show us the divergences where p < .05
bootstrap_analysis_unfamiliar <- analyze_boot_splines(bootstrapped_unfamiliar)
## Warning: Calling boot-splines from this function is deprecated. Please use
## `analyze_time_bins` for boot-splines.
summary(bootstrap_analysis_unfamiliar)
## Divergences:
## 1:   920 - 1940

Cluster Analysis

alpha = .20
num_sub = length(unique((response_unfamiliar_time$ParticipantName)))
threshold_t = qt(p = 1 - alpha/2, 
                 df = num_sub-1)

# differences in positive direction...
df_timeclust <- make_time_cluster_data(response_unfamiliar_time, 
                                      test= "t.test",
                                      paired = FALSE,
                                      predictor_column = "Condition", 
                                      threshold = threshold_t,
                                      formula = ArcSin ~ Condition) 

plot(df_timeclust) +
  ylab("T-Statistic")

summary(df_timeclust)
## Test Type:    t.test 
## Predictor:    Condition 
## Formula:  ArcSin ~ Condition 
## Summary of Clusters ======
##    Cluster Direction SumStatistic StartTime EndTime
## 1        1  Positive     4.002310         0      20
## 2        2  Positive     2.766681       110     140
## 3        3  Positive     1.299990       160     170
## 4        4  Positive     1.324528       430     440
## 5        5  Positive     1.377453       480     490
## 6        6  Positive    19.538362       550     720
## 7        7  Positive   158.974954       760    2020
## 8        8  Positive     7.876571      2050    2120
## 9        9  Positive     2.997240      2330    2360
## 10      10  Positive     5.915391      2430    2490
## 11      11  Positive     4.402373      2510    2560
## 12      12  Positive    14.382520      2580    2710
## 13      13  Positive     1.369323      3150    3160
## 14      14  Positive     4.312072      4510    4560
## 15      15  Positive     5.147612      4580    4620
## 16      16  Positive     3.612785      4760    4790
## 17      17  Positive     1.408695      4810    4820
## 18      18  Positive     1.336772      4850    4860
## 19      19  Positive     3.040730      4960    4990
## 20      20  Negative    -9.604390      3780    3870
## 21      21  Negative    -1.720093      3930    3940
## 22      22  Negative    -2.837912      3960    3990
## 23      23  Negative    -1.332187      5430    5440
## 24      24  Negative    -1.353890      5460    5470
clust_analysis <- analyze_time_clusters(df_timeclust, within_subj=FALSE, paired=FALSE, samples=5000, parallel=TRUE)
clust_analysis
## Test Type:    t.test 
## Predictor:    Condition 
## Formula:  ArcSin ~ Condition 
## Null Distribution   ====== 
##  Mean:        0.2779 
##  2.5%:        -148.1146 
## 97.5%:        149.6981 
## Summary of Clusters ======
##    Cluster Direction SumStatistic StartTime EndTime Probability
## 1        1  Positive     4.002310         0      20      0.9766
## 2        2  Positive     2.766681       110     140      0.9916
## 3        3  Positive     1.299990       160     170      0.9994
## 4        4  Positive     1.324528       430     440      0.9992
## 5        5  Positive     1.377453       480     490      0.9986
## 6        6  Positive    19.538362       550     720      0.6908
## 7        7  Positive   158.974954       760    2020      0.0400
## 8        8  Positive     7.876571      2050    2120      0.9056
## 9        9  Positive     2.997240      2330    2360      0.9872
## 10      10  Positive     5.915391      2430    2490      0.9454
## 11      11  Positive     4.402373      2510    2560      0.9690
## 12      12  Positive    14.382520      2580    2710      0.7790
## 13      13  Positive     1.369323      3150    3160      0.9986
## 14      14  Positive     4.312072      4510    4560      0.9708
## 15      15  Positive     5.147612      4580    4620      0.9544
## 16      16  Positive     3.612785      4760    4790      0.9782
## 17      17  Positive     1.408695      4810    4820      0.9980
## 18      18  Positive     1.336772      4850    4860      0.9992
## 19      19  Positive     3.040730      4960    4990      0.9862
## 20      20  Negative    -9.604390      3780    3870      0.8740
## 21      21  Negative    -1.720093      3930    3940      0.9934
## 22      22  Negative    -2.837912      3960    3990      0.9904
## 23      23  Negative    -1.332187      5430    5440      0.9992
## 24      24  Negative    -1.353890      5460    5470      0.9990
plot(clust_analysis)

Onset-contingent Analysis

onsets <- make_onset_data(unfamiliar, onset_time = 0, 
                          fixation_window_length = 100, target_aoi='Animate')
## Warning in make_onset_data(unfamiliar, onset_time = 0, fixation_window_length = 100, : Smoothing in make_onset_data() using fixation_window_length_rows is experimental. We
##             recommend looking closely at the output to validate it.
# participants' ability to orient to the trial target overall:
plot(onsets, predictor_columns = "Condition") + theme(legend.text=element_text(size=5))

onset_switches <- make_switch_data(onsets, predictor_columns = c("Condition","TrialNumber"))

# visualize subject's switch times
plot(onset_switches, predictor_columns = "Condition")
## Warning: Removed 18 rows containing non-finite values (stat_boxplot).
## Warning: Removed 18 rows containing missing values (geom_point).

# center predictor:
onset_switches$FirstAOIC <- ifelse(onset_switches$FirstAOI == 'Animate', .5, -.5)
onset_switches$FirstAOIC <- onset_switches$FirstAOIC - mean(onset_switches$FirstAOIC, na.rm=TRUE)
onset_switches$ConditionC <- ifelse(onset_switches$Condition == 'Informative', .5, -.5)
onset_switches$ConditionC <- onset_switches$ConditionC - mean(onset_switches$ConditionC)
onset_switches$TrialNumberC <- onset_switches$TrialNumber - mean(onset_switches$TrialNumber)

# build model:
model_switches <- lmer(FirstSwitch ~ (FirstAOIC+ConditionC+TrialNumberC)^2 + (1 | Trial) + (1 | ParticipantName), data=onset_switches, REML=FALSE)
summary(model_switches)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: FirstSwitch ~ (FirstAOIC + ConditionC + TrialNumberC)^2 + (1 |  
##     Trial) + (1 | ParticipantName)
##    Data: onset_switches
## 
##      AIC      BIC   logLik deviance df.resid 
##   4069.4   4104.0  -2024.7   4049.4      226 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.6664 -0.6696 -0.2483  0.4656  3.1635 
## 
## Random effects:
##  Groups          Name        Variance  Std.Dev. 
##  ParticipantName (Intercept) 2.603e+05 5.102e+02
##  Trial           (Intercept) 5.212e-11 7.220e-06
##  Residual                    1.460e+06 1.208e+03
## Number of obs: 236, groups:  ParticipantName, 48; Trial, 6
## 
## Fixed effects:
##                         Estimate Std. Error t value
## (Intercept)              1523.43     109.20  13.951
## FirstAOIC                 677.97     169.29   4.005
## ConditionC               -150.68     218.37  -0.690
## TrialNumberC               38.90      48.23   0.807
## FirstAOIC:ConditionC      472.28     338.67   1.395
## FirstAOIC:TrialNumberC    162.53     107.72   1.509
## ConditionC:TrialNumberC   -60.93      96.18  -0.633
## 
## Correlation of Fixed Effects:
##             (Intr) FrAOIC CndtnC TrlNmC FAOIC:C FAOIC:T
## FirstAOIC    0.047                                     
## ConditionC  -0.004 -0.079                              
## TrialNumbrC  0.021  0.035  0.047                       
## FrstAOIC:CC -0.078  0.047  0.048 -0.004                
## FrsAOIC:TNC  0.018 -0.011 -0.004 -0.124  0.035         
## CndtnC:TrNC  0.045  0.001  0.023  0.023  0.030  -0.098
drop1(model_switches,~.,test="Chi")
## Single term deletions
## 
## Model:
## FirstSwitch ~ (FirstAOIC + ConditionC + TrialNumberC)^2 + (1 | 
##     Trial) + (1 | ParticipantName)
##                         Df    AIC     LRT  Pr(Chi)    
## <none>                     4069.4                     
## FirstAOIC                1 4082.9 15.4979 8.26e-05 ***
## ConditionC               1 4067.8  0.4704   0.4928    
## TrialNumberC             1 4068.0  0.6482   0.4208    
## FirstAOIC:ConditionC     1 4069.3  1.9327   0.1645    
## FirstAOIC:TrialNumberC   1 4069.6  2.2640   0.1324    
## ConditionC:TrialNumberC  1 4067.8  0.4010   0.5266    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# within Informative, to look for speed-up over trials:
model_switches_inf <- lmer(FirstSwitch ~ (FirstAOIC+TrialNumberC)^2 + (1 | Trial) + (1 | ParticipantName), data=onset_switches %>% filter(Condition == 'Informative'), REML=FALSE)
summary(model_switches_inf)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: FirstSwitch ~ (FirstAOIC + TrialNumberC)^2 + (1 | Trial) + (1 |  
##     ParticipantName)
##    Data: onset_switches %>% filter(Condition == "Informative")
## 
##      AIC      BIC   logLik deviance df.resid 
##   2061.9   2081.4  -1023.9   2047.9      113 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.6604 -0.6678 -0.2250  0.3166  3.2937 
## 
## Random effects:
##  Groups          Name        Variance Std.Dev.
##  ParticipantName (Intercept)  167598   409.4  
##  Trial           (Intercept)       0     0.0  
##  Residual                    1374153  1172.2  
## Number of obs: 120, groups:  ParticipantName, 24; Trial, 6
## 
## Fixed effects:
##                        Estimate Std. Error t value
## (Intercept)            1440.435    137.363  10.486
## FirstAOIC               928.657    234.293   3.964
## TrialNumberC              8.316     67.433   0.123
## FirstAOIC:TrialNumberC  151.426    152.923   0.990
## 
## Correlation of Fixed Effects:
##             (Intr) FrAOIC TrlNmC
## FirstAOIC   -0.033              
## TrialNumbrC  0.068  0.025       
## FrsAOIC:TNC  0.015  0.033 -0.225
drop1(model_switches_inf,~.,test="Chi")
## Single term deletions
## 
## Model:
## FirstSwitch ~ (FirstAOIC + TrialNumberC)^2 + (1 | Trial) + (1 | 
##     ParticipantName)
##                        Df    AIC     LRT   Pr(Chi)    
## <none>                    2061.9                      
## FirstAOIC               1 2074.5 14.5976 0.0001331 ***
## TrialNumberC            1 2059.9  0.0152 0.9019056    
## FirstAOIC:TrialNumberC  1 2060.8  0.9695 0.3247973    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(onset_switches %>%
    filter(Condition == 'Informative') %>%
    mutate(Half = ifelse(TrialNumber <= 9, 'First', 'Last')) %>%
    group_by(ParticipantName,Half,FirstAOI) %>%
    summarise(
      FirstSwitch = mean(FirstSwitch,na.rm=T)
    ) %>%
    group_by(Half,FirstAOI) %>%
    summarise(
      M = mean(FirstSwitch,na.rm=T),
      SD = sd(FirstSwitch,na.rm=T)
    ))
## Source: local data frame [6 x 4]
## Groups: Half [?]
## 
##    Half    FirstAOI         M        SD
##   (chr)      (fctr)     (dbl)     (dbl)
## 1 First     Animate 1578.9048 1017.4942
## 2 First Not_Animate 1065.0278 1359.5333
## 3 First          NA       NaN        NA
## 4  Last     Animate 1960.6905 1318.1607
## 5  Last Not_Animate  543.5882  416.9676
## 6  Last          NA       NaN       NaN

```